package com.huawei.bitfun.visitors;

import com.intellij.openapi.editor.Document;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;

public class VisitorUtils {
    public static PsiElement findElementAtPosition(PsiFile psiFile, int lineNumber, int columnNumber) {
        PsiDocumentManager manager = PsiDocumentManager.getInstance(psiFile.getProject());
        Document document = manager.getDocument(psiFile);
        if (document == null) {
            return null;
        }
        int offset = document.getLineStartOffset(lineNumber - 1) + columnNumber - 1;
        return psiFile.findElementAt(offset);
    }
}